import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../components/Home.vue";
import Login from "../components/Login.vue";
import Welcome from "../components/welcome.vue";
import Users from "../components/user/users.vue";
import Role from "../components/right/role.vue";
import Right from "../components/right/right.vue";
import Cate from "../components/goods/Cate.vue"
import Params from "../components/goods/Params.vue"
import Goods from '../components/goods/List.vue'
import addGood from '../components/goods/addGood.vue'
import Order from '../components/order/order.vue'
import Report from '../components/report/report.vue'
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/login"
  },
  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue")
  },
  {
    path: "/login",
    name: "login",
    component: Login
  },
  {
    path: "/home",
    name: "home",
    component: Home,
    redirect: "/home/welcome",
    beforeEnter: (to, from, next) => {
      if (from.path == "/login") {
        return next();
      }
      if (sessionStorage.getItem("token")) {
        return next();
      }
      next("/login");
    },
    children: [
      {
        path: "welcome",
        name: "welcome",
        component: Welcome
      },
      {
        path: "users",
        name: "users",
        component: Users
      },
      {
        path: "roles",
        name: "roles",
        component: Role
      },
      {
        path: "rights",
        name: "rights",
        component: Right
      },
      {
        path: "categories",
        name: "categories",
        component: Cate
      },
      {
        path: "params",
        name: "params",
        component: Params
      },
      {
        path: "goods",
        name: "goods",
        component: Goods
      },
      {
        path: "goods/addgood/:id",
        name: "addgood",
        component: addGood,
        props: true
      },
      {
        path: "orders",
        name: "orders",
        component: Order,
        props: true
      },
      {
        path: "reports",
        name: "reports",
        component: Report,
        props: true
      }
    ]
  }
];

const router = new VueRouter({
  routes
});

export default router;
